package com.macro.mall.portal.controller;

import com.macro.mall.common.api.CommonPage;
import com.macro.mall.common.api.CommonResult;
import com.macro.mall.model.BmsLeaveApproval;
import com.macro.mall.portal.service.BmsLeaveApprovalService;
import com.macro.mall.query.BmsLeaveApprovalQuery;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@Api(tags = "BmsLeaveApprovalController")
@Tag(name = "BmsLeaveApprovalController", description = "请假")
@RequestMapping("/leaveApproval")
public class BmsLeaveApprovalController {

    @Resource
    private BmsLeaveApprovalService leaveApprovalService;

    @ApiOperation("分页查询")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> list(@RequestBody BmsLeaveApprovalQuery query) {
        try {
            List<BmsLeaveApproval> list = leaveApprovalService.findList(query);
            return CommonResult.success(CommonPage.restPage(list));
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }

    @ApiOperation("创建请假")
    @RequestMapping(value = "/create", method = RequestMethod.POST)
    @ResponseBody
    public CommonResult<?> create(@RequestBody BmsLeaveApprovalQuery query) {
        try {
            int i = leaveApprovalService.create(query);
            return CommonResult.success("创建成功");
        } catch (Exception e) {
            return CommonResult.failed(e.getMessage());
        }
    }
}
